require(quantmod)
require(PerformanceAnalytics)

getSymbols('^GSPC', from='1900-01-01')

d <- index(GSPC)
getMonth <- function(i)
{
  as.numeric(format(i, format="%m"))
}
firstHalf <- function(i)
{
  ifelse(getMonth(i) <= 4 || getMonth(i) >= 11, 1, 0)
}

hold1 <- unlist(lapply(d, firstHalf))
hold2 <- 1-hold1
hold1 <- xts(hold1, d)
hold2 <- xts(hold2, d)

perf <- merge(hold1 * ROC(GSPC[,4], type='discrete', n=1), hold2 * ROC(GSPC[,4], type='discrete', n=1))
colnames(perf) <- c("Nov - Apr", "May - Oct")
charts.PerformanceSummary(perf)
